/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-03-22 16:18:10
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-08-16 19:00:17
 */
export default {
  // 判断数据类型
  type: (data) => {
    // const toString = Object.prototype.toString;
    const dataType = toString
      .call(data)
      .replace(/\[object\s(.+)\]/, "$1")
      .toLowerCase();
    return dataType;
  },

  isObject: (obj: object): boolean => typeof obj === "object" && obj != null,

  isFormData: (val) => {
    return typeof FormData !== "undefined" && val instanceof FormData;
  },
  isPromise: (obj) => {
    return typeof obj === "object" && typeof obj.then === "function";
  },
  isArrayBufferView: (val) => {
    let result;
    if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
      result = ArrayBuffer.isView(val);
    } else {
      result = val && val.buffer && val.buffer instanceof ArrayBuffer;
    }
    return result;
  },
};
